﻿using Ideaa.Data.Infrastructure;
using Ideaa.Data.Models;
using Ideaa.Services.Base;
using Ideaa.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ideaa.Services.Services
{
    public class SuggestionService : BaseService, ISuggestionService
    {
        public SuggestionService(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        public void Add(Suggestion suggestion)
        {
            if (suggestion == null)
            {
                throw new NullReferenceException("Suggestion could not be found!");
            }

            this.unitOfWork.Suggestions.Add(suggestion);
            this.unitOfWork.SaveChanges();
        }

        public void Delete(Suggestion suggestion)
        {
            if (suggestion == null)
            {
                throw new NullReferenceException("Suggestion could not be found!");
            }

            this.unitOfWork.Suggestions.Delete(suggestion);
            this.unitOfWork.SaveChanges();
        }


        public IList<Suggestion> GetSuggestionsByIdeaId(int ideaId)
        {
            if (ideaId == null || ideaId < 1)
            {
                throw new NullReferenceException("Suggestion could not be found!");
            }

            return this.unitOfWork.Suggestions.All().Where(x => x.IdeaId == ideaId).ToList();

        }
    }
}
